#ifndef QHDRCAMERA_H
#define QHDRCAMERA_H

#include "QNativeCamera.h"
#include <QGenericMatrix>
#include <QThreadPool>

class HdrThread :public QRunnable
{

public:
    HdrThread(QImage*,QImage*);

private:
    QImage* image;
    QImage* result;

protected:
    void run();
};


class QHdrCamera : public QNativeCamera
{
    Q_OBJECT
    Q_CLASSINFO("Author", "Sebastiano Galazzo")
    Q_CLASSINFO("Email", "sebastiano.galazzo@gmail.com")

    Q_PROPERTY(qreal exposureRange  READ exposureRange  WRITE setExposureRange  NOTIFY exposureRangeChanged)
    Q_PROPERTY(unsigned short shots  READ shots  WRITE setShots NOTIFY shotsChanged)

public:
    explicit QHdrCamera(QDeclarativeItem *parent = 0);

    unsigned short shots();
    void setShots(unsigned short value);

    qreal exposureRange();
    void setExposureRange(qreal value);

    static float brightness( const char r, const char g, const char b);
    //static float gray( const char r, const char g, const char b);
    static float gray( const float r, const float g, const float b);
    static float saturation( const float r, const float g, const float b);
    static void laplace(QImage& in, QImage& out);
    //static int gauss(QImage& in, QImage& out, double sigma=0.35);
    static int gauss(QImage& in, QImage& out, double sigma=0.2);
    static void mul(QVector<QImage*>& ins, QImage& out, int k=0);
    static void add(QVector<QImage*>& ins, QImage& out, bool average=true);

signals:
    void started();
    void finished(QString pathResultImage, QString pathOriginalImage);
    void merging();

    void shotsChanged(int value);
    void exposureRangeChanged(qreal value);

    void processedShot1();
    void processedShot2();
    void processedShot3();

public slots:
    void captureImage();

private slots:
    void process();
    void imageAvailable(int,QVideoFrame);
    void imageCaptured ( int id, const QImage & preview );

private:
    /*QImage shot1;
    QImage shot2;
    QImage shot3;*/
    QVector<QImage*> shot;    
    QVector<QImage*> tShot;
    QVector<QVideoFrame> vFrame;

    /*QImage tImage1;
    QImage tImage2;
    QImage tImage3;*/

    unsigned short m_shots;
    qreal m_exposureRange;

    static QMatrix3x3 convol;
};

#endif // QHDRCAMERA_H
